package reit.ass3;

import java.util.concurrent.Callable;

import org.apache.log4j.Logger;


/**
 * The Class CallableSimulateStayInAsset simulates a stay of a single customer in asset.
 */
class CallableSimulateStayInAsset implements Callable<Float> {
	
	
	/** The length of day. */
	public static final int fLENGTH_OF_DAY = 24000;

	/** The m customer. */
	private final Customer mCustomer;

	/** The m stay duration. */
	private final long mStayDuration;

	/** The logger. */
	private Logger fLogger;

	/**
	 * Instantiates a new callable simulate stay in asset.
	 *
	 * @param customer the customer
	 * @param duration the duration
	 */
	public CallableSimulateStayInAsset(final Customer customer, final long duration) {
		fLogger = Logger.getLogger(CallableSimulateStayInAsset.class);
		this.mCustomer = customer;
		this.mStayDuration = duration * fLENGTH_OF_DAY;
	}

	/* (non-Javadoc)
	 * @see java.util.concurrent.Callable#call()
	 */
	@Override
	public Float call() throws Exception {
		fLogger.info(MyStringBuilder.buildString("Customer:",
				mCustomer.getName(), " is staying for ",
				Long.toString(mStayDuration/fLENGTH_OF_DAY), " days"));
		Thread.sleep(mStayDuration);
		return mCustomer.getDmgPercent();
	}

}
